-
-
Notifications
You must be signed in to change notification settings - Fork 170
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL #1658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
No idea what the CI is complaining about, tbh. I'm still quite unsure about how we should handle |
7357644
to
4adcc5c
Compare
Currently just a couple minor clippy things, add
Yep, when in doubt let's go with |
397aafc
to
4dd2a16
Compare
The error reporting of the |
Ah sorry I missed that error. It's because you're using a Rust enum, which is not quite compatible with a C enum (because it's undefined behavior to create a Rust enum from an invalid value). This can be fixed by using the (I put up #1660 to improve this error message.) |
6fd55f5
to
45b4059
Compare
Oof, that's embarrassing, the last merge request was only a few weeks ago and I've already forgotten about it. I needed some iterations for the addressing stuff ( |
|
||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct PciRootBridgeIoAccess<TAddr> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The uefi-raw crate doesn't normally use generics. I think in the spec the address
is treated as u64
in all cases, even though for for pci specifically the u64
is broken down into subfields, so let's do that and leave higher-level abstractions to the uefi
crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the interface itself in the spec accepts a u64
, because they use the same struct for pci
, memory
and io
.
But the pci
one is supposed to be filled by something like this:
#define EFI_PCI_ADDRESS(bus, dev, func, reg) \
(UINT64) ( \
(((UINTN) bus) << 24) | \
(((UINTN) dev) << 16) | \
(((UINTN) func) << 8) | \
(((UINTN) (reg)) < 256 ? ((UINTN) (reg)) : (UINT64) (LShiftU64 ((UINT64) (reg), 32))))
My thought process was: If they could have used templates/generics in their interface, they would have done it there.
At least I would like to have the PCI addressing somehow as part of the unsafe API, because otherwise you can't use it without reading the UEFI spec. Do you have an alternative suggestion? The only alternative I was able to come up with, was a union
and that's IMHO ugly to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to get rid of the generics, we could:
impl Into<u64> for PciIoAddress {
fn into(self) -> u64 {
unsafe { core::mem::transmute(self) }
}
}
And then use it like so:
let addr = PciIoAddress::new(1, 3, 3).with_register(7);
(raw_proto.pci.read)(
raw_proto,
PciRootBridgeIoProtocolWidth::UINT32,
addr.into(), // API takes u64, we convert PciIoAddress to it
1,
&mut raw as *mut u32 as *mut c_void
).to_result()?;
EDIT: Just refactored it that way
6901e11
to
7814063
Compare
Checklist